<template>
  <!-- 添加或修改流程进度配置对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body width="80vw">
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <form-block-title title="基础信息"/>
      <el-form-item label="业务标志" prop="businessKey">
        <el-input v-model="form.businessKey" placeholder="请输入业务标志"/>
      </el-form-item>
      <el-form-item label="节点名称" prop="nodeName">
        <el-input v-model="form.nodeName" placeholder="请输入节点名称"/>
      </el-form-item>
      <el-form-item label="节点值" prop="nodeValue">
        <el-input v-model="form.nodeValue" placeholder="请输入节点值"/>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input-number v-model="form.sort" :min="0" controls-position="right"/>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" placeholder="请输入内容" type="textarea"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">保 存</el-button>
      <el-button @click="cancel">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getConfigure, addConfigure, updateConfigure, exportConfigure } from '@/api/processSchedule/configure'
import FormBlockTitle from '@/components/ScFormBlockTitle/index'

export default {
  name: 'Edit',
  components: { FormBlockTitle },
  data() {
    return {
      id: -1,
      // 弹出层标题
      title: '录入信息',
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {}
      ,
      // 表单校验
      rules: {}
    }

  },
  created() {
  },
  methods: {
    init(id) {
      //编辑页面加载数据
      if (id && id !== -1) {
        this.id = id
        getConfigure(id).then(response => {
          this.form = response.data
        })
      }
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessKey: null,
        nodeName: null,
        nodeValue: null,
        sort: null,
        remark: null
      }

      this.resetForm('form')
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateConfigure(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess('修改成功')
                this.open = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            addConfigure(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess('新增成功')
                this.open = false
                this.$emit('refreshDataList')
              }
            })
          }
        }
      })
    }
  }
}
</script>
